﻿@using CkSoftware.GroupMe.Sdk.TestWeb.Helpers
@using CkSoftware.GroupMe.Sdk.TestWeb.Models
@using TwitterBootstrapMVC.Controls
@model BotConfigurationModel
@{
    ViewBag.Title = "Bot Testing example";
}

<div class="page-header">
    <h1>Bot testing example</h1>
</div>

<p>On this page, you can configure and test the bot ability of the GroupMe .NET SDK.</p>

@if (SessionConfiguration.IsConfigValueIsSet<string>(SessionConfiguration.GroupMeBotApiKeyConfigKey))
{
    <h2>Bot-Group-Configuration @Html.Bootstrap().Icon(Icons.ok).Class(!SessionConfiguration.IsConfigValueIsSet<string>(SessionConfiguration.GroupMeGroupIdConfigKey) ? "hidden" : string.Empty)</h2>
    if (!BotHelper.IsBotStarted())
    {
        using (FormBuilder<BotConfigurationModel> form = Html.Bootstrap().Begin(new Form("StartBot").Type(FormType.Horizontal)))
        {
            @form.ControlGroup().TextBoxFor(m => m.GroupMeGroupId).Label().LabelText("Group ID where the bot should interact")

            @form.ControlGroup().TextBoxFor(m => m.BotName).Label().LabelText("Bot Name").ShowRequiredStar(true)
            @form.ControlGroup().TextBoxFor(m => m.AvatarUrl).Label().LabelText("Avatar Url")
            @form.ControlGroup().CheckBoxFor(m => m.RegisterCallback).Label().LabelText("Register group callback")
            @form.ControlGroup().CustomControls(Html.Bootstrap().SubmitButton().Text("Start Bot"))
        }
    }
    else
    {
        using (FormBuilder<BotConfigurationModel> form = Html.Bootstrap().Begin(new Form("DestroyBot").Type(FormType.Horizontal)))
        {
            @form.ControlGroup().CustomControls(Html.Bootstrap().SubmitButton().Text("Destroy Bot"))
        }
        
        <hr />
        <h2>Send message to configured group</h2>
        using (FormBuilder<BotConfigurationModel> form = Html.Bootstrap().Begin(new Form("SendMessage").Type(FormType.Horizontal)))
        {
            @form.ControlGroup().TextBox("message").Label().LabelText("Message")
            @form.ControlGroup().TextBox("attachmentImageUrl").Label().LabelText("Image Url as attachment")
            @form.ControlGroup().CustomControls(Html.Bootstrap().SubmitButton())
        }
    }
}
else
{
    <h2>Bot-API-Configuration</h2>
    <p>First, you need to configure the GroupMe .NET SDK with a valid API key. This key can be obtained at the top of the bots page: <a href="https://dev.groupme.com/bots">https://dev.groupme.com/bots</a>.</p>

    using (FormBuilder<BotConfigurationModel> form = Html.Bootstrap().Begin(new Form("Configure").Type(FormType.Horizontal)))
    {
        @form.ControlGroup().TextBoxFor(m => m.ApiKey).Label().LabelText("GroupMe API-Key")
        @form.ControlGroup().CustomControls(Html.Bootstrap().SubmitButton())
    }
}